<?php

use Drupal\shusy_product\Entity\ShusyProduct;
use Drupal\shusy_product\Entity\ShusyProductStandard;

function ssy_live_product_shusy_product_edit_page(ShusyProduct $product) {
  $e = ssy_live_product_new_single(FALSE, ['product_id' => $product->id]);
  if (empty($e->id)) {
    $standards = $product->standards();
    $e->name = $product->name;
    $e->price_type = 1;
    $amounts = [];
    foreach ($standards as $standard) {
      if ($standard instanceof ShusyProductStandard) {
        $amounts[] = $standard->amount;
      }
    }
    $min = min($amounts);
    $max = max($amounts);
    $e->price = $min;
    $e->price2 = $max;
    if ($max > $min) {
      $e->price_type = 2;
    }
    $e->save();
  }
  module_load_include('inc', 'ssy_live_product', 'ssy_live_product.forms');
  return drupal_get_form('ssy_live_product_ssy_live_product_entity_form', $e, $product);
}
